#方法一
class Solution:
    def moveZeroes(self, nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        i = j = 0
        n = len(nums)
        flag = False
        while i < n:
            if nums[i] == 0:
                while j < n:
                    j += 1
                    if j == n:
                        flag =True # 到结尾都是0
                        break
                    if nums[j] != 0:
                        nums[i], nums[j] = nums[j], nums[i]
                        i += 1
                        j = i
                        break
            else:
                i += 1
                j += 1
            if flag:# 跳出死循环
                break
    
    # 方法二
    class Solution:
    def moveZeroes(self, nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        n = len(nums)
        for i in range(n):
            if nums[i] == 0:
                for j in range(i + 1, n):
                    if nums[j] != 0:
                        nums[i], nums[j] = nums[j], nums[i]
                        break
# 方法三
class Solution:
    def moveZeroes(self, nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        n = len(nums)
        cur = 0
        for i in range(n):
            if nums[i] != 0:
                nums[cur] = nums[i]
                cur += 1
        for j in range(cur, n):
            nums[j] = 0